package sword.T49;

/**
 * @Author: 18362
 * @Create: 2022-04-09 18:45:49 星期六
 */

class Solution {
    public int nthUglyNumber(int n) {
        int i2 = 0, i3 = 0, i5 = 0, min = 0;
        int[] res = new int[n];
        res[0] = 1;
        for (int i=1; i<n; ++i) {
            int a2 = res[i2] * 2, a3 = res[i3] * 3, a5 = res[i5] * 5;
            min = Math.min(a2, Math.min(a3, a5));
            if (a2 == min) i2++;
            if (a3 == min) i3++;
            if (a5 == min) i5++;
            res[i] = min;
        }
        return res[n];
    }
}